const http = require("http");
const https = require("https");
const cheerio = require("cheerio");

//创建服务
function Crawler(imgUrl, callback) {
  http.get(imgUrl, (res) => {
    var imageData = "";
    //触发接收事件data
    res.on("data", (chunk) => {
      //接收数据，将数据一点点的追加到没我们定义的空字符串中
      imageData += chunk;
    });
    //触发接收完成时间end
    res.on("end", () => {
      var $ = cheerio.load(imageData);
      callback(imageData);
    });
  });
}
module.exports = Crawler;
